package hxy.dragon.secure

import kotlin.test.*

class EndToEndEncryptionTest {
    @Test
    fun testEncryptionMessageFormat() {
        // 测试消息
        val message = "Hello, this is a secret message!"
        
        // 模拟接收方的公钥（在实际应用中，这应该是真实的ED25519公钥）
        val recipientPublicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPSEOTVqftlcxz24oP8erbsq/XqF9cOSjJu9zH4BCJjC test@example.com"
        
        // 验证加密消息格式
        assertTrue(message.isNotEmpty())
        assertTrue(recipientPublicKey.startsWith("ssh-ed25519 "))
        
        // 验证SSH公钥解析
        try {
            val parsedKey = parseSshEd25519PublicKey(recipientPublicKey)
            assertEquals(32, parsedKey.size) // ED25519公钥应该是32字节
        } catch (e: Exception) {
            fail("Failed to parse SSH ED25519 public key: ${e.message}")
        }
    }
    
    @Test
    fun testPrivateKeyParsing() {
        // 模拟接收方的私钥（在实际应用中，这应该是真实的私钥）
        val recipientPrivateKey = """-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACD0hDk1an7ZXMc9uKD/Hq27Kv16hfXDkoybvcx+AQiYwgAAAJi5zU0Tuc1N
EwAAAAtzc2gtZWQyNTUxOQAAACD0hDk1an7ZXMc9uKD/Hq27Kv16hfXDkoybvcx+AQiYwg
AAAED4NfJ/T2amYrgStidoIsphfaFc30lGax/C4RA6YC1be/SEOTVqftlcxz24oP8erbsq
/XqF9cOSjJu9zH4BCJjCAAAAE2FvaGFuaG9uZ3poaUBxcS5jb20BAg==
-----END OPENSSH PRIVATE KEY-----"""
        
        // 验证私钥解析
        try {
            val parsedKey = parseOpenSSHPrivateKey(recipientPrivateKey)
            assertEquals(32, parsedKey.size) // 解析出的私钥种子应该是32字节
        } catch (e: Exception) {
            fail("Failed to parse OpenSSH private key: ${e.message}")
        }
    }
}